package test07.instrospction;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

/**
 * 内省操作 - 获取 BeanInfo 对象
 * @Author lzp
 * @Date 2024-03-28
 */
public class test01 {
    public static void main(String[] args) throws Exception {

        //获取 JavaBean 对象的 BeanInfo 对象
        BeanInfo beanInfo = Introspector.getBeanInfo(Person.class,Object.class);

        //获取 JavaBean 的属性列表
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            Class<?> propertyType = propertyDescriptor.getPropertyType();
            String typeName = propertyType.getSimpleName();
            String name = propertyDescriptor.getName();

            System.out.print(" 属性类型 " + typeName);
            System.out.println(" 属性名称 " + name);

        }

    }
}
